# _*_ coding: utf-8 _*_
# @Time : 2020/11/17 16:19
# @Author : moran office
# File : 腾讯视频_py.py
# Software : PyChram

# https://apd-e5c86fd45cc6e4d1e777a7a2bbf78a1e.v.smtcdns.com/vipts.tc.qq.com/
# AnHZHaoDk6asCd0-9QtlAzqdGnCzUnI4b3EdF_aOa6Zo/uwMROfz2r5zAoaQXGdGnC2df644E7D3uP8M8pmtgwsRK9nEL/
# V09b7dpjPB-7TKOFs0PY-kHciptVSMl1K0SAfxSXjPRsxop8ZAGUTOvilvXMsAwR4zcEBSD7revMwAwY-kwc7eMW_
# 54reOSAqSFxNl1RWrSEiWspB5aL4qFJMqkrzKJxXd-LU9VVaxXptNRF3BbnfRARrsyA50kLVc_TcGhSz88/
# 018_r0034rmwzpe.321002.1.ts?index=18&start=209875&end=220000&brs=34564176&bre=36346979&ver=4
# &token=960b19b79b55831dea42cd5e8063415d

#https://apd-e5c86fd45cc6e4d1e777a7a2bbf78a1e.v.smtcdns.com/vipts.tc.qq.com/
# AnHZHaoDk6asCd0-9QtlAzqdGnCzUnI4b3EdF_aOa6Zo/uwMROfz2r5zAoaQXGdGnC2df644E7D3uP8M8pmtgwsRK9nEL/
#V09b7dpjPB-7TKOFs0PY-kHciptVSMl1K0SAfxSXjPRsxop8ZAGUTOvilvXMsAwR4zcEBSD7revMwAwY-kwc7eMW_
# 54reOSAqSFxNl1RWrSEiWspB5aL4qFJMqkrzKJxXd-LU9VVaxXptNRF3BbnfRARrsyA50kLVc_TcGhSz88/
# 019_r0034rmwzpe.321002.1.ts?index=19&start=220000&end=232500&brs=36346980&bre=38846439&ver=4
# &token=3238d841e5b20639055d6781700bcd32

#https://apd-e5c86fd45cc6e4d1e777a7a2bbf78a1e.v.smtcdns.com/vipts.tc.qq.com/
# AnHZHaoDk6asCd0-9QtlAzqdGnCzUnI4b3EdF_aOa6Zo/uwMROfz2r5zAoaQXGdGnC2df644E7D3uP8M8pmtgwsRK9nEL/
# V09b7dpjPB-7TKOFs0PY-kHciptVSMl1K0SAfxSXjPRsxop8ZAGUTOvilvXMsAwR4zcEBSD7revMwAwY-kwc7eMW_
# 54reOSAqSFxNl1RWrSEiWspB5aL4qFJMqkrzKJxXd-LU9VVaxXptNRF3BbnfRARrsyA50kLVc_TcGhSz88/
# 020_r0034rmwzpe.321002.1.ts?index=20&start=232500&end=239875&brs=38846440&bre=40762911&ver=4
# &token=897876d6a7bb4a7feffa1150c36bc02b

import requests
import os

path = 'E:/腾讯视频/'

refer = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
}
if (os.path.exists(path)):
    print('目录已存在')
else:
    os.makedirs(path)

start = 232500
end = 239875
index = 20
brs = 38846440
bre = 40762911

for index in range(20, 200):
    print(f'第{index}次执行。。。。。')
    url = f'https://apd-2831d63b715749bcba16dfd689ebc4c4.v.smtcdns.com/vipts.tc.qq.com/ACDqshrAQeDUqjKJw46-gHC2bzXGtcntXP6jArV8vIOQ/uwMROfz2r5zAoaQXGdGnC2df644E7D3uP8M8pmtgwsRK9nEL/CmIfBx0pNerFpiVPM_XctzABm4oCcext7IJXtDlh7Qur1QAJWxWKwh1XiEV0v4o6zNhHdxX9TiRvt865ZDTBTlZF7UNtmChpkaui37viLHjULr1Dk5zA7tSYPUn3nHEanva-tDyrDf30Zz7G3w_SW3f8vZ6bacBgAYPUiFnB8EE/0{index}_r0034rmwzpe.321002.1.ts?index={index}&start={start}&end={end}&brs={brs}&bre={bre}&ver=4'
    res = requests.get(url, headers = refer)
    try:
        f = open(path + str(index) + '.ts', 'wb')
        f.write(res.content)
        f.close()
    except:
       print("保存ts文件报错")
       continue
    start = end
    end += 7375
    brs = bre
    bre += 1917471




